package com.mav.service.iml;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.mav.mapper.StudentMapper;
import com.mav.pojo.PageResult;
import com.mav.pojo.Student;
import com.mav.pojo.StudentQueryParam;
import com.mav.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class StudentServiceIml implements StudentService {
    @Autowired
    StudentMapper studentMapper;
    @Override
    public PageResult<Student> page(StudentQueryParam studentQueryParam) {
        PageHelper.startPage(studentQueryParam.getPage(),studentQueryParam.getPageSize());
        List<Student> list=studentMapper.list(studentQueryParam.getName(),studentQueryParam.getDegree(),studentQueryParam.getClazzId());
        Page<Student> page=(Page<Student>) list;
        return new PageResult<>(page.getTotal(),page.getResult());

    }

    @Override
    public void deleteById(List<Integer> ids) {
        studentMapper.deleteById(ids);
    }

    @Override
    public void add(Student student) {
        student.setCreateTime(LocalDateTime.now());
        student.setUpdateTime(LocalDateTime.now());
        studentMapper.insert(student);
    }

    @Override
    public Student findById(Integer id) {
        return studentMapper.findById(id);
    }

    @Override
    public void updateById(Student student) {
        student.setUpdateTime(LocalDateTime.now());
        studentMapper.updateById(student);
    }

    @Override
    public void disciplinaryViolation(Integer id, Short score) {
        studentMapper.disciplinaryViolation(id,score);
    }
}
